/**
 * 必须提前引入 layui
 */
layui.use(['layer', 'jquery'], function () {
    var layer = layui.layer, $ = layui.jquery
    var complete = function (XMLHttpRequest) {
        if (XMLHttpRequest.responseJSON != undefined
            && XMLHttpRequest.responseJSON.hasOwnProperty('code')
            && XMLHttpRequest.responseJSON.code != 0) {
            if (XMLHttpRequest.responseJSON.code == 10) {// 您还未登录或者登录已经失效，请重新登录
                layer.msg('您还未登录或者登录已经失效，即将跳转到登录页面', {icon: 2, anim: 5, time: 5000});
                setTimeout(function () {
                    window.location.href = '/auth/login'
                }, 5000)
                return;
            }
            layer.msg(XMLHttpRequest.responseJSON.msg, {icon: 2, anim: 6, time: 5000});
            console.warn(XMLHttpRequest.responseJSON)
        } else if (XMLHttpRequest.responseJSON == undefined ||
            (XMLHttpRequest.responseJSON != '' && !XMLHttpRequest.responseJSON.hasOwnProperty('code'))) {
            layer.alert(XMLHttpRequest.responseText)
            console.warn(XMLHttpRequest.responseText)
        }
    }
    // 封装一个app
    var app = {
        ajax: function (config) {
            config.complete = complete
            return $.ajax(config)
        }
    }
    // 加载插件
    window.app = app
});

